<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <input type="text" placeholder="商品标题" v-model="item.title">
    <input type="text" placeholder="商品价格" v-model="item.price">
    <input type="text" placeholder="商品销量" v-model="item.num">
    <input type="button"value="添加商品" @click="add()">
    <template>
        <el-table :data="arr" style="width: 100%">
            <el-table-column type="index" label="序号" width="180"></el-table-column>
            <el-table-column prop="title"  label="商品标题" width="180"></el-table-column>
            <el-table-column prop="price"  label="价格" width="180"></el-table-column>
            <el-table-column prop="num"  label="销量" width="180"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </template>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function() {
            return {
                arr:[{title:"SU7",price:200000,num:27000},
                    {title:"han",price:300000,num:15000},
                    {title:"qin",price:69000,num:18000},
                    {title:"yuan",price:150000,num:12000}],
                item:{title:"",price:"",num:""}
            }
        },
        methods:{
            handleDelete(index, row) {
               v.arr.splice(index,1);
               v.$message.warning(row.title+"被删除了");
            },
            add(){
                //push(v.item):给JS数组添加元素
                v.arr.push(v.item)
            }
        }
    })
</script>
</html>